package com.dv.web.controller.warehouse;

import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.core.page.TableDataInfo;
import com.dv.common.enums.BusinessType;
import com.dv.driverless.domain.WarehouseLocation;
import com.dv.driverless.domain.vo.WarehouseLocationInitVo;
import com.dv.driverless.domain.vo.WarehouseLocationSteelCoilVo;
import com.dv.driverless.service.IWarehouseLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库位信息Controller
 *
 * @author ruoyi
 * @date 2023-04-10
 */
@Api
@RestController
@RequestMapping("/warehouse/location")
public class WarehouseLocationController extends BaseController {
    @Autowired
    private IWarehouseLocationService warehouseLocationService;

    /**
     * 查询库位信息列表
     */
    @ApiOperation("库位信息")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseLocation warehouseLocation) {
        startPage();
        List<WarehouseLocationSteelCoilVo> list =
                warehouseLocationService.selectWarehouseLocationList(warehouseLocation);
        return getDataTable(list);
    }

    /**
     * 获取库位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:location:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(warehouseLocationService.selectWarehouseLocationById(id));
    }

    /**
     * 新增库位信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:location:add')")
    @Log(title = "库位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseLocation warehouseLocation) {
        return toAjax(warehouseLocationService.insertWarehouseLocation(warehouseLocation));
    }

    /**
     * 修改库位信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:location:edit')")
    @Log(title = "库位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseLocation warehouseLocation) {
        return toAjax(warehouseLocationService.updateWarehouseLocation(warehouseLocation));
    }

    /**
     * 删除库位信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:location:remove')")
    @Log(title = "库位信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(warehouseLocationService.deleteWarehouseLocationByIds(ids));
    }

    /**
     * 初始化库位信息
     */
    @ApiOperation("初始化库位信息")
    @Log(title = "初始化库位信息", businessType = BusinessType.INSERT)
    @PostMapping("/initialization")
    public AjaxResult initLocation(@RequestBody WarehouseLocationInitVo warehouseLocationInitVo) {
        return toAjax(warehouseLocationService.initLocation(warehouseLocationInitVo));
    }

    /**
     * 初始化库位信息
     */
    @ApiOperation("锁库位")
    @Log(title = "锁库位", businessType = BusinessType.UPDATE)
    @PostMapping("/lockLocation")
    public AjaxResult lockLocation(@RequestBody List<Long> ids) {
        return toAjax(warehouseLocationService.lockLocation(ids));
    }


}
